home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / Scripts / enhancer.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  1.2 KB  |  54 lines

  1. #
  2. # The Python Imaging Library
  3. # $Id: enhancer.py,v 1.1.1.1 1998/08/18 13:07:58 sjoerd Exp $
  4. #
  5. # this demo script creates four windows containing an image and a slider.
  6. # drag the slider to modify the image.
  7.  
  8. from Tkinter import *
  9. import Image, ImageTk, ImageEnhance
  10. import sys
  11.  
  12. #
  13. # enhancer widget
  14.  
  15. class Enhance(Frame):
  16.     def __init__(self, master, image, name, enhancer, lo, hi):
  17.     Frame.__init__(self, master)
  18.  
  19.     # set up the image
  20.     self.tkim = ImageTk.PhotoImage(image.mode, image.size)
  21.     self.enhancer = enhancer(image)
  22.     self.update("1.0") # normalize
  23.  
  24.     # image window
  25.     Label(self, image=self.tkim).pack()
  26.  
  27.     # scale
  28.     s = Scale(self, label=name, orient=HORIZONTAL,
  29.           from_=lo, to=hi, resolution=0.01,
  30.           command=self.update)
  31.     s.set(self.value)
  32.         s.pack()
  33.  
  34.     def update(self, value):
  35.     self.value = eval(value)
  36.     self.tkim.paste(self.enhancer.enhance(self.value))
  37.  
  38. #
  39. # main
  40.  
  41. root = Tk()
  42.  
  43. im = Image.open(sys.argv[1])
  44.  
  45. im.thumbnail((200, 200))
  46.  
  47. Enhance(root, im, "Color", ImageEnhance.Color, 0.0, 4.0).pack()
  48. Enhance(Toplevel(), im, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).pack()
  49. Enhance(Toplevel(), im, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).pack()
  50. Enhance(Toplevel(), im, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).pack()
  51.  
  52. root.mainloop()
  53.